package com.lfy.controller;


import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.lfy.domain.vo.BackGroundVO;
import com.lfy.modules.blog.domain.SocialEntity;
import com.lfy.modules.blog.domain.dto.article.CommentDTO;
import com.lfy.domain.dto.FeedBackDTO;
import com.lfy.modules.blog.domain.group.WebGroup;
import com.lfy.modules.blog.domain.vo.web.*;
import com.lfy.modules.blog.service.SocialService;
import com.lfy.modules.common.domain.PageResultVO;
import com.lfy.modules.common.domain.R;
import com.lfy.modules.safety.aop.anno.CurrentLimit;
import com.lfy.modules.safety.limit.strategy.LimitStrategyEnum;
import com.lfy.service.WebService;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.util.List;
import java.util.concurrent.TimeUnit;

/**
 *  web接口
 *
 * @author <a href="https://www.lvfeiy.top">lfy</a>
 * @date 2024/5/15 22:57
 */
@RequestMapping("/web")
@RestController
public class WebController {
    @Resource
    private WebService webService;




    /**
     * 首页
     * @param url uri
     * @return 首页数据
     */
    @GetMapping("/home")
    @CurrentLimit(time = 1,once = 15,nuit = TimeUnit.MINUTES,strategy = LimitStrategyEnum.Ip)
    @CurrentLimit(time = 10,once = 40,nuit = TimeUnit.MINUTES,strategy = LimitStrategyEnum.Ip)
    @CurrentLimit(time = 1,once = 80,nuit = TimeUnit.HOURS,strategy = LimitStrategyEnum.Ip)
    public R<HomeVO> home(@RequestParam("url") String url) {
        return webService.home(url);
    }
    /**
     * 文章列表
     */
    @GetMapping("/get/article")
    @CurrentLimit(time = 1,once = 15,nuit = TimeUnit.MINUTES,strategy = LimitStrategyEnum.Ip)
    @CurrentLimit(time = 10,once = 40,nuit = TimeUnit.MINUTES,strategy = LimitStrategyEnum.Ip)
    @CurrentLimit(time = 1,once = 80,nuit = TimeUnit.HOURS,strategy = LimitStrategyEnum.Ip)
    public R<PageResultVO<ArticleShowVO>> getArticle(@RequestParam("pageSize") Integer pageSize, @RequestParam("pageNum") Integer pageNum,
                                                     @RequestParam("url") String url){
        return webService.getArticleList(pageNum,pageSize,null,url);
    }

    /**
     * 获取反馈列表
     */
    @GetMapping("/get/feedback")
    public R<PageResultVO<FeedbackWebVO>> getFeedback(@RequestParam("pageSize") Integer pageSize,
                                                      @RequestParam("pageNum") Integer pageNum,
                                                      @RequestParam("url") String url){
        return webService.getFeedbackList(pageNum,pageSize,url);
    }
    /**
     * 反馈信息
     */
    @PostMapping("/feedback")
    @CurrentLimit(time = 1,once = 4,nuit = TimeUnit.MINUTES,strategy = LimitStrategyEnum.Ip)
    @CurrentLimit(time = 10,once = 10,nuit = TimeUnit.MINUTES,strategy = LimitStrategyEnum.Ip)
    @CurrentLimit(time = 1,once = 15,nuit = TimeUnit.HOURS,strategy = LimitStrategyEnum.Ip)
    public R<Void> feedback(@RequestBody @Validated FeedBackDTO dto){
        return webService.feedback(dto);
    }
    /**
     * 文章详情
     */
    @GetMapping("/article/detail/{url}/{id}")
    @CurrentLimit(time = 1,once = 15,nuit = TimeUnit.MINUTES,strategy = LimitStrategyEnum.Ip)
    @CurrentLimit(time = 10,once = 40,nuit = TimeUnit.MINUTES,strategy = LimitStrategyEnum.Ip)
    @CurrentLimit(time = 1,once = 80,nuit = TimeUnit.HOURS,strategy = LimitStrategyEnum.Ip)
    public R<ArticleTextVO> articleDetail(@PathVariable("id") Long id,@PathVariable("url") String url){
        return webService.getArticleDetail(id,url);
    }

    /**
     * 获取评论列表
     * @param id 文章id
     * @return 评论列表
     */
    @GetMapping("/get/comment")
    public R<List<ArticleCommentVO>> getComment(@RequestParam("id") Long id){
        return webService.getComment(id);
    }
    /**
     * 评论
     */
    @PostMapping("/comment")
    @CurrentLimit(time = 1,once = 6,nuit = TimeUnit.MINUTES,strategy = LimitStrategyEnum.Ip)
    @CurrentLimit(time = 10,once = 20,nuit = TimeUnit.MINUTES,strategy = LimitStrategyEnum.Ip)
    public R<Void> comment(@RequestBody @Validated(WebGroup.class) CommentDTO dto){
        return webService.comment(dto);
    }

    /**
     * 说说列表
     */
    @GetMapping("/get/say")
    public R<?> getSay(@RequestParam("length") Integer length, @RequestParam("url") String url){
        return webService.getSayList(length,url);
    }
    /**
     * 单独获取封面及签名
     */
    @GetMapping("/get/backGround")
    public R<BackGroundVO> getBackGround(@RequestParam("url") String url){
        return webService.getBackGround(url);
    }

    /**
     * 背景音乐及社交账号
     */
    @GetMapping("/get/social")
    public R<SocialEntity> getSocial(@RequestParam("url") String url) {
        return webService.getSocial(url);
    }
    @PostMapping("/goods/article/{id}")
    public R<Void> goodsArticle(@PathVariable("id") Long id){
        return webService.goodsArticle(id);
    }
}
